<%--
  Created by IntelliJ IDEA.
  User: LuoQing
  Date: 2022/1/11
  Time: 19:37
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>添加等级职位</title>
</head>
<style>
    img{
        position: relative;
        border-radius: 50%;
    }
    form {
        background: -webkit-linear-gradient(bottom, #CCCCCC, #EEEEEE 175px);
        background: -moz-linear-gradient(bottom, #CCCCCC, #EEEEEE 175px);
        background: linear-gradient(bottom, #CCCCCC, #EEEEEE 175px);
        margin: auto;
        position: relative;
        width: 450px;
        height: 280px;
        font-family: Tahoma, Geneva, sans-serif;
        font-size: 14px;
        font-style: italic;
        line-height: 24px;
        font-weight: bold;
        color: #09C;
        text-decoration: none;
        border-radius: 10px;
        padding: 10px;
        border: 1px solid #999;
        border: inset 1px ;
        -webkit-box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.3);
        -moz-box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.3);
        box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.3);
    }
    input {
        width: 375px;
        display: block;
        border: 1px solid #999;
        height: 25px;
        -webkit-box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.3);
        -moz-box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.3);
        box-shadow: 0px 0px 8px rgba(0, 0, 0, 0.3);
    }
    #cc {
        width: 100px;
        position: absolute;
        right: 20px;
        bottom: 20px;
        background: #09C;
        color: #fff;
        font-family: Tahoma, Geneva, sans-serif;
        height: 30px;
        border-radius: 15px;
        border: 1px solid #999;
    }

    #cc {
        background: #fff;
        color: #09C;
    }
    body {

        font: normal 11px auto;

        color: #4f6b72;

    }

    a {

        color: #c75f3e;

    }

    #mytable {

        width: 700px;

        padding: 0;

        margin: 0;

    }

    caption {

        padding: 0 0 5px 0;

        width: 700px;

        font: italic 11px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;

        text-align: right;

    }

    td {

        border-right: 1px solid #C1DAD7;

        border-bottom: 1px solid #C1DAD7;

        background: #fff;

        font-size:11px;

        padding: 6px 6px 6px 12px;

        color: #4f6b72;

    }

    td.alt {

        background: #F5FAFA;

        color: #797268;
    }

</style>
<body>
<form>
    角色名称：<input name="descn"><br/><br/>
    现有角色：<select id="js"></select><br/><br/>
    <input id="cc" type="button" onclick="addRoles()" value="添加" >
</form>
</body>
<script src="/js/jquery-3.3.1.js"></script>
<script src="/js/jquery.serializejson.js"></script>
<script type="text/javascript">
    queryAllRoles()
    function addRoles() {
        let value = document.getElementsByName("descn")[0].value;
        if(check()){
            $.getJSON("/suc/AddRoles",{descn:value},function (data) {
                    if(data==1){
                        alert("添加成功")
                        window.location="/lqym/quan.jsp"
                    }
                    if (data==2){
                        alert("角色上限不能继续添加")
                    }
                    if(data==0){
                        alert("当前角色已有")
                    }
            })
        }
    }
    function check() {
        var dengji = document.getElementsByName("descn")[0].value;
        if (dengji=="") {
            alert("未填写角色名称")
            return false;
        }
        return true;
    }
    function queryAllRoles() {
        $.getJSON("/suc/AllRoles",function (data) {
            $("#js").empty()
            for(let i=0;i<data.length;i++){
                $("#js").append(" <option value="+data[i].rid+">"+data[i].descn+"</option>")
            }
        })
    }
</script>
</html>
